package com.jinzhi.jzweb.controller.moduleConfig;


import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.jinzhi.common.utils.Result;
import com.jinzhi.jzweb.pojo.ModuleConfig.JzJinzhuanDispositionTopic;
import com.jinzhi.jzweb.service.moduleConfig.IJzJinzhuanDispositionTopicService;
import io.swagger.annotations.*;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author JingChangTian
 * @since 2023-06-16
 */
@Controller
@RequestMapping("/jz-jinzhuan-disposition-topic")
@Api(value = "模块任务管理", tags = "模块任务管理")
public class JzJinzhuanDispositionTopicController {
    /**
     * 业务层，调用重写mybatisPuls，或其他业务方法
     */
    private final IJzJinzhuanDispositionTopicService dispositionTopicService;

    public JzJinzhuanDispositionTopicController(IJzJinzhuanDispositionTopicService dispositionTopicService) {
        this.dispositionTopicService = dispositionTopicService;
    }

    @ApiOperation(value = "模块任务页面入口", notes = "模块任务页面入口")
    @ApiResponses({@ApiResponse(code = 0, message = "操作成功"),
            @ApiResponse(code = 500, message = "服务器内部异常")})
    @GetMapping(value = "/moduleTopic")
    @RequiresPermissions("jzweb:disposition:topic")
    public String moduleEntrance(){
        return "/ini/";
    }

    @ApiOperation(value = "新增任务信息", notes = "新增任务信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "JzJinzhuanDispositionTopic", value = "JzJinzhuanDispositionTopic", required = true, dataType = "JzJinzhuanDispositionTopic"),
    })
    @ApiResponses({@ApiResponse(code = 0, message = "操作成功"),
            @ApiResponse(code = 500, message = "服务器内部异常")})
    @ResponseBody
    @RequestMapping(value = "/insert", method = RequestMethod.POST)
    public Result<String> insert(@RequestBody JzJinzhuanDispositionTopic jzJinzhuanDispositionTopic){
        Boolean aBoolean = dispositionTopicService.insert(jzJinzhuanDispositionTopic);
        return aBoolean ? Result.ok() : Result.fail();
    }


    @ApiOperation(value = "修改任务信息", notes = "修改任务信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "JzJinzhuanDispositionTopic", value = "JzJinzhuanDispositionTopic", required = true, dataType = "JzJinzhuanDispositionTopic"),
    })
    @ApiResponses({@ApiResponse(code = 0, message = "操作成功"),
            @ApiResponse(code = 500, message = "服务器内部异常")})
    @ResponseBody
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public Result<String> update(@RequestBody JzJinzhuanDispositionTopic jzJinzhuanDispositionTopic){
        Boolean aBoolean = dispositionTopicService.updateById(jzJinzhuanDispositionTopic);
        return aBoolean ? Result.ok() : Result.fail();
    }


    @ApiOperation(value = "批量删除任务信息", notes = "批量删除任务信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ids", value = "ids", required = true, dataType = "List<Long>"),
    })
    @ApiResponses({@ApiResponse(code = 0, message = "操作成功"),
            @ApiResponse(code = 500, message = "服务器内部异常")})
    @ResponseBody
    @PostMapping(value = "/deleteBatchIds")
    public Result<String> deleteBatchIds(@RequestParam("ids[]") Long[] ids){
        Boolean aBoolean = dispositionTopicService.deleteBatchIds(Arrays.asList(ids));
        return aBoolean ? Result.ok() : Result.fail();
    }


    @ApiOperation(value = "根据模块id查询任务信息", notes = "根据模块id查询任务信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "id", required = true, dataType = "Long"),
    })
    @ApiResponses({@ApiResponse(code = 0, message = "操作成功"),
            @ApiResponse(code = 500, message = "服务器内部异常")})
    @ResponseBody
    @RequestMapping(value = "/getTopicByModuleId", method = RequestMethod.POST)
    public Result<List<JzJinzhuanDispositionTopic>> getTopicByModuleId(@RequestParam Long id){
        List<JzJinzhuanDispositionTopic> dispositionTopics = dispositionTopicService.selectList(
                new EntityWrapper<JzJinzhuanDispositionTopic>().
                        eq("is_deleted",0).
                        eq("module_id",id).
                        orderBy("creater_date",true));
        return Result.ok(dispositionTopics);
    }
}
